<template>
  <el-dialog
    v-model="state.centerDialogVisible"
    title="上报实施成果"
    width="50%"
    align-center
    @open="openHandler"
    @close="handleClose"
  >
    <el-form
      :model="formInline"
      :rules="rules"
      ref="formRef"
      class="demo-form-inline"
      label-width="120px"
    >
      <el-form-item label="所属项目集">
        <el-input disabled v-model="formInline.projectSetName" placeholder="" />
      </el-form-item>
      <el-form-item label="项目集编号">
        <el-input disabled v-model="formInline.projectSetCode" placeholder="" />
      </el-form-item>
      <el-form-item label="计划时间范围">
        <el-date-picker
          disabled
          v-model="formInline.planStartTime"
          type="daterange"
          range-separator="-"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          value-format="YYYY-MM-DD"
        />
      </el-form-item>
      <el-form-item label="所属项目">
        <el-input disabled v-model="formInline.projectName" placeholder="" />
      </el-form-item>
      <el-form-item label="项目编号">
        <el-input disabled v-model="formInline.projectId" placeholder="" />
      </el-form-item>

      <el-form-item label="是否关注项目">
        <el-radio-group v-model="formInline.interestStatus" disabled>
          <el-radio label="1">是</el-radio>
          <el-radio label="-1">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="所属阶段">
        <el-input
          disabled
          v-model="formInline.projectStage"
          placeholder=""
        />
      </el-form-item>
      <el-form-item label="处理部门">
        <el-input
          disabled
          v-model="formInline.departmentName"
          placeholder=""
        />
      </el-form-item>
      <el-form-item label="所属任务">
        <el-input disabled v-model="formInline.taskName" placeholder="" />
      </el-form-item>
      <el-form-item label="任务编码">
        <el-input disabled v-model="formInline.projectTaskId" placeholder="" />
      </el-form-item>
      <el-form-item label="处理人">
        <el-input
          disabled
          v-model="formInline.responsibleUserName"
          placeholder=""
        />
      </el-form-item>
      <p class="oneline" style="font-size: 12px; color: #cccccc">形象进度汇报</p>
      <el-form-item label="进度文档" class="oneline" prop="files">
        <!-- //pic为了验证图片是必传的 -->
        <FileMinioUpload
          :show-button="state.isLook!=1"
          :businessType="21"
          :associationId="formInline.projectTaskId"
          :restriction="state.isLook!=1"
          :restrictionLimit="9"
          v-model:files="formInline.files"
        />
      </el-form-item>
      <el-form-item label="实际完成时间">
        <el-date-picker
          disabled
          v-model="formInline.completeTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="选择实际完成时间"
        />
      </el-form-item>
      <el-form-item label="实际情况描述" class="oneline">
        <el-input
          :disabled="state.isLook==1"
          v-model="formInline.description"
          show-word-limit
          type="textarea"
        />
      </el-form-item>
      <el-form-item label="是否存在问题">
        <el-radio-group v-model="formInline.isProblem"  :disabled="state.isLook==1">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="formInline.isProblem===1" label="问题概述" class="oneline">
        <el-input
          :disabled="state.type"
          v-model="formInline.problemDescription"
          show-word-limit
          type="textarea"
        />
      </el-form-item>
      <!-- 全部人员 -->
      <el-row>


      <el-col :span="24" v-if="state.type">
        <CommonTitle titleName="其他信息"></CommonTitle>
      </el-col>

      <el-col  v-if="state.type">
        <el-form-item label="申请人" class="oneline">
          <el-input disabled v-model="formInline.applyUserName" placeholder="" />
        </el-form-item>
      </el-col>

      <el-col  v-if="state.type">
        <el-form-item label="申请部门" class="oneline">
          <el-input
            disabled
            v-model="formInline.applyDepartmentName"
            placeholder=""
          />
        </el-form-item>
      </el-col>
      <el-col  v-if="state.type">
        <el-form-item label="创建时间" class="oneline">
          <el-input disabled v-model="formInline.createTime" placeholder="" />
        </el-form-item>
      </el-col>
    </el-row>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="state.centerDialogVisible = false" class="button_cancel2">取消</el-button>
        <el-button type="primary" @click="submitHandler" v-if="state.isLook!=1" class="button_view">
          确定
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import upload from '@/components/uploadCom/upload.vue'
import { ref, reactive } from 'vue'
import {
  ElDialog,
  ElForm,
  ElCol,
  ElRow,
  ElFormItem,
  ElMessage
} from 'element-plus'
// import FileUpload from '@/components/FileUpload.vue'
import FileMinioUpload from "@/components/FileMinioUpload.vue";
import { implementationResult } from '@/api/project'
import CommonTitle from '@/components/CommonTitle.vue'
import {taskApi} from "@/api/investment";
let centerDialogVisible = ref(false)
const formInline = reactive({
  files: [],
  description: '',
  problemDescription: '',
  isProblem: 0,
  planStartTime: []
})
const state = reactive({
  projectTaskId: '',
  itemId: '',
  type: 0,
  isLook:'',
  businessId: '',
  centerDialogVisible: false,
  projectRow: {}
})
const rules = {
  files: [{ required: true, message: '文件不能为空', trigger: 'blur' }]
}


//弹框打开前的回调
const openHandler = () => {
  let obj = {
    projectTaskId: state.projectTaskId || '',
    businessId: state.businessId || '',
    itemId: state.itemId || ''
  }
  taskApi.getImplementationAchievements(obj).then((res) => {
    if (res.code == '200') {
      let obj = { ...res.data, ...res.data?.taskInfo }
      for (const key in obj) {
        if (key == 'files') {
          formInline[key] = obj[key] || []
          continue
        }
        if (key == 'planStartTime') {
          formInline[key] = obj[key] ? [obj[key], obj['planEndTime']] : []
          continue
        }
        if (key == 'isProblem') {
          formInline[key] = 0
          continue
        }
        formInline[key] = obj[key] || ''
      }
    }
  })
}

//弹框关闭
const emits = defineEmits(['refreshList']);
const handleClose = () => {
  for (const key in formInline) {
    formInline[key] = ''
  }
  emits('refreshList');
}

const formRef = ref(null);
//上报提交
const submitHandler = () => {
  formRef.value.validate((valid, fields) => {
    if (valid) {
      taskApi
        .saveImplementationAchievements({
          files: formInline.files,
          projectTaskId: formInline.projectTaskId,
          isProblem: formInline.isProblem,
          description: formInline.description,
          completeTime: formInline.completeTime,
          itemId: state.itemId,
          problemDescription: formInline.problemDescription
        })
        .then((res) => {
          if (res.code == '200') {
            state.centerDialogVisible = false
            ElMessage.success('操作成功')
            emits('refreshList');
          }
        })
    }
  })
}
defineExpose({
  state
})
</script>
<style lang="scss" scoped></style>
